package com.yuuzy.controller;

import com.yuuzy.dto.PatientPageQueryDTO;
import com.yuuzy.result.PageResult;
import com.yuuzy.result.Result;
import com.yuuzy.service.PatientService;
import com.yuuzy.service.ReportService;
import com.yuuzy.vo.MonthlyDataVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 检索统计
 */
@RestController
@RequestMapping("/diagnose/report")
@Api(tags = "检索统计相关接口")
@Slf4j
public class ReportController {
	@Autowired
	private ReportService reportService;

	/**
	 * 全字段检索分页查询
	 *
	 * @param patientPageQueryDTO
	 * @return
	 */
	@GetMapping("/retrieval")
	@ApiOperation("全字段检索分页查询")
	public Result<PageResult> retrievalPageQuery(PatientPageQueryDTO patientPageQueryDTO) {
		log.info("全字段检索分页查询:{}", patientPageQueryDTO);
		PageResult pageResult = reportService.retrievalPageQuery(patientPageQueryDTO);
		return Result.success(pageResult);
	}

	/**
	 * 病历统计
	 *
	 * @param year
	 * @return
	 */
	@GetMapping("/monthlyData")
	@ApiOperation("根据统计年份计算每月录入人数")
	public Result<MonthlyDataVO> getMonthlyData(@RequestParam int year) {
		log.info("病历统计：{}", year);
		return Result.success(reportService.getMonthlyData(year));
	}

	/**
	 * 导出患者信息到Excel
	 *
	 * @param response
	 * @param patientPageQueryDTO
	 */
	@GetMapping("/export")
	@ApiOperation("导出患者信息到Excel")
	//todo：可修改：前端传来的是list<PatientPageQueryVO> patients,后端直接根据patient.id查询数据库即可
	public void exportToExcel(HttpServletResponse response, PatientPageQueryDTO patientPageQueryDTO) {
		log.info("导出患者信息:{}", patientPageQueryDTO);
		reportService.exportPatientInfo(response, patientPageQueryDTO);
	}

	/**
	 * 根据患者id导出图像
	 *                                      
	 * @param id
	 * @param response
	 */
	@GetMapping("/images/{id}")
	@ApiOperation("根据患者id导出图像")
	public void exportImagesById(@PathVariable Integer id, HttpServletResponse response) {
		log.info("导出单个患者图像:{}", id);
		reportService.exportImagesById(id, response);
	}
	@GetMapping("/images")
	@ApiOperation("导出所有患者图像")
	public void exportImages(HttpServletResponse response, PatientPageQueryDTO patientPageQueryDTO){
		log.info("导出所有患者图像:{}", patientPageQueryDTO);
		reportService.exportImages(response, patientPageQueryDTO);
	}
}
